package cn.fintecher.pangolin.service.dataimp.scheduled;

import cn.fintecher.pangolin.service.dataimp.elastic.*;
import cn.fintecher.pangolin.common.utils.RepositoryUtil;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Auther: xiaqun
 * @Description: 删除数据导入信息调度
 * @Date: 19:23 2019/11/4
 */

@Component
@EnableScheduling
public class DeleteESScheduled {
    private static final Logger log = LoggerFactory.getLogger(DeleteESScheduled.class);

    @Autowired
    private PersonalImportModelElastic personalImportModelElastic;

    @Autowired
    private PaymentRecordModelElastic paymentRecordModelElastic;

    @Autowired
    private PaymentRecordElastic paymentRecordElastic;

    @Autowired
    private PreRecordModelElastic preRecordModelElastic;

    @Autowired
    private PreRecordElastic preRecordElastic;

    @Autowired
    private StopCaseModelElastic stopCaseModelElastic;

    @Autowired
    private LeaveCaseModelElastic leaveCaseModelElastic;

    @Autowired
    private WarningModelElastic warningModelElastic;

    @Autowired
    private WarningElastic warningElastic;

    @Autowired
    private WorkOrderModelElastic workOrderModelElastic;

    @Autowired
    private OtherRecordElastic otherRecordElastic;

    @Autowired
    private DistributeModelElastic distributeModelElastic;

    @Scheduled(cron = "0 0 0 * * ?")
    private void downloadRecord() {
        BoolQueryBuilder builder = new BoolQueryBuilder();
        builder.must(QueryBuilders.matchPhraseQuery("flag", 1));
        log.info("1、删除已确认的案件导入数据");
        RepositoryUtil.deleteData(personalImportModelElastic, builder);
        log.info("2、删除已撤销的对账单导入数据");
        RepositoryUtil.deleteData(paymentRecordModelElastic, builder);
        RepositoryUtil.deleteData(paymentRecordElastic, builder);
        log.info("3、删除已撤销的委前催记导入数据");
        RepositoryUtil.deleteData(preRecordModelElastic, builder);
        RepositoryUtil.deleteData(preRecordElastic, builder);
        log.info("4、删除已撤销的停催案件导入数据");
        RepositoryUtil.deleteData(stopCaseModelElastic, builder);
        log.info("5、删除已撤销的留案案件导入数据");
        RepositoryUtil.deleteData(leaveCaseModelElastic, builder);
        log.info("6、删除已撤销的警告信息导入数据");
        RepositoryUtil.deleteData(warningModelElastic, builder);
        RepositoryUtil.deleteData(warningElastic, builder);
        log.info("7、删除已撤销的的工单导入数据");
        RepositoryUtil.deleteData(workOrderModelElastic, builder);
        RepositoryUtil.deleteData(otherRecordElastic, builder);
        log.info("9、删除已确认的分案导入数据");
        RepositoryUtil.deleteData(distributeModelElastic, builder);
    }
}
